import java.sql.Connection;
import java.sql.Date;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class Main1 {
	 public static void displayAll(){
			String URL = "jdbc:mysql://localhost:3306/test";
			String driverName = "com.mysql.jdbc.Driver";
			String sql = "select * from students";
			String userName = "root";
			String password = "java123";
			Connection conn = null;		
			try {//201521123025
				Class.forName(driverName);
				conn = DriverManager.getConnection(URL,userName,password);
				Statement statement = conn.createStatement();
				ResultSet resultSet = statement.executeQuery(sql);
				while(resultSet.next()){
					
					String stuno = resultSet.getString("stuno");
					String name=resultSet.getString("name");
					Date date = resultSet.getDate("birthdate");
					System.out.print("stuno="+stuno+" name="+name+" birthdate="+date);
				}
				
			} catch (SQLException e) {
				e.printStackTrace();
			} catch (ClassNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}finally{
				if(conn!=null)
					try {
						conn.close();
					} catch (SQLException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				conn = null;
			}
	 } 	
	public static void main(String[] args) {
		displayAll();
	}

}
